<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumBuckets = function (hamsters) {
      let res = 0;
      // 长度
      const n = hamsters.length;
      for (let i = 0; i < n; i++) {
        // 遍历到房屋时
        if (hamsters[i] === 'H') {
          // 若右边有空位
          if (hamsters[i + 1] === '.') {
            // 则在右边放置水桶
            res++;
            // 水桶的位置、水桶右边的位置不再考虑
            i += 2;
          } else if (hamsters[i - 1] === '.') { // 若左边有空位
            // 则在左边放置水桶
            res++;
          } else { // 否则无解
            return -1;
          }
        }
      }
      return res;
    };
    console.log(minimumBuckets(street = "H..H"))
  </script>
</body>

</html>